//系统模块
import React, { Component } from 'react';
import { systemStyle as styles } from '../../../styles';

import {
    View,
    ScrollView,
} from 'react-native';

var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;

import { EditResumeAction, UpdateResumeAction } from '../../actions/systemAction';      //加载action
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

import Sysbasic from './every/sysbasic';
import Sysworkstate from './every/sysworkstate';
import Sysresumestate from './every/sysresumestate';
import Sysotherinstall from './every/sysotherinstall';

class SystemIndex extends Component {
    // 初始化模拟数据
    constructor(props) {            //构造器只执行一次
        super(props);
    };

    //加载后渲染页面
    componentDidMount() {
        this.props.actions.EditResumeAction(); //初始化查询
    }

    render() {
        const { resume } = this.props.xz_resume.data;
        return (
            <View style={styles.container}>
                <ScrollView>
                    <Sysbasic resume={resume} navigation={this.props.navigation} />
                    <Sysworkstate resume={resume} />
                    <Sysresumestate
                        resume={resume}
                        msg={this.props.xz_resume.data.msg}
                        actions={this.props.actions} />
                    <Sysotherinstall resume={resume} navigation={this.props.navigation} />
                </ScrollView>
            </View>
        )
    }
}

//组合action
var actions = {
    EditResumeAction,
    UpdateResumeAction,
}

//连接state到props
const mapStateToProps = state => {
    return {
        xz_resume: state.EditResumeReducer             //自己的reducers
    }
}

//连接action
const mapDispatchToProps = (dispatch) => {
    return {
        actions: bindActionCreators(actions, dispatch)
    }
}

//导出组合好的组件(组合后状态改变重新渲染组合组件的页面)
export default connect(
    mapStateToProps, mapDispatchToProps
)(SystemIndex);